#ifndef SENDMESSAGETHREAD_H
#define SENDMESSAGETHREAD_H

#include <QObject>
#include <QThread>
#include <QSerialPort>
#include "ui_mainwindow.h" // 包含ui_mainwindow.h头文件
#include <QQueue>
#include  <QTimer>

class SendMessageThread : public QThread
{
    Q_OBJECT
public:
    explicit SendMessageThread(QSerialPort *serial, Ui::MainWindow *ui, QObject *parent = nullptr);
    // 其他成员函数和信号声明
    int send_ok;
    int send_flag;


public slots:
    void sendMessage();

signals:
    void messageSent(const QString &message);


protected:
    void run() override;
private slots:
    void processSendQueue(); // 确保声明了这个函数
    void processNext();

private:
    QSerialPort *serial;
    Ui::MainWindow *ui; // 添加对ui的成员变量引用
    QByteArray sendData;
    void handleSend(QCheckBox *checkBox, QLineEdit *lineEdit, const QString &prefix);
    QQueue<std::function<void()>> commandQueue;
    QTimer commandTimer;  // 声明 QTimer 成员变量
};

#endif // SENDMESSAGETHREAD_H
